import { _decorator, Vec3 , Node} from 'cc';
import { SkillManager } from './SkillManager';
import { EBuff, EGroup, EntityType, ESkill } from '../Config/Enum';
import ObjectPoolManager from '../Core/ObjectPoolManager';
import { Collider2D } from 'cc';
import { PlayerManager } from '../PlayerManager';
import { buffConfig, SkillConfig } from '../Config/SkillConfig';
import { EnemyManager } from '../EnemyManager';
import { BattleManager } from '../BattleManager';

const { ccclass } = _decorator;
// 武学三 灭绝剑法
// 符文1 - 玄阴蚀骨 冰冻概率40%
// 符文2 - 冰封万里 TODO减速50%
// 符文3 - 北冥吸星 被冰冻的敌人受伤增加30%


@ccclass('EmeiSkill3')
export class EmeiSkill3 extends SkillManager {
    private _hasSplit = false;
    runeId
    effectChance
    buffTypeList
    buffDuration
    

    // 新增标志：是否是主子弹（由玩家直接发射的子弹）
    private isMasterBullet = true;
    pm
    _originalDirection: Vec3;
    enemyDirection: Vec3;

    init(type: ESkill, pm: PlayerManager) {
        // 重置所有状态
        this.pm = pm;
        //this.reset();
        super.init(type, pm);

        this._originalDirection = this.direction.clone(); 

        
        // 只有主子弹需要重置分裂标志
        if (this.isMasterBullet) {
            this._hasSplit = false;
        }


        // 其他符文效果
        switch (this.runeId) {
            case 1:

                break;
            case 2: //
                break;  
            case 3:
 
                break;
            default:

                break;
        }
    }

    protected onHitEnemy(self, other: Collider2D): void {
        super.onHitEnemy(self, other);

        switch (this.runeId) {
            case 1: //冰冻
            console.log("emei3 onHit case1")
                this.applyBuffToEnemy(this.em, 0.5,EBuff.Freeze, 0, 2)
                break;
            case 2:
                this.applyBuffToEnemy(this.em, 0.5,EBuff.Slow, 0.5, 3); // 减速50%，持续3秒
                break;
            case 3: 
                if(this.em.isFreezed){
                    this.applyBuffToEnemy(this.em, 0.5,EBuff.Vulnerable, 0.8, 2); // 减速50%，持续3秒
                }
            break;
            default:
                break;
        }



    }



}